5-E
Simple site for the info you need...
  • Add Local Admin
  • Backup Dogecoin Wallet
  • Batch Start Powershell
  • Copy A File(s) To All Users On A PC
  • CPU Load Test
  • Disable Users
  • Email Group Members
  • Email With Powershell
  • Exchange Total Size
  • Export to XLSX
  • Export User Cert
  • Get System Info
  • Import Active Directory Module
  • Last Login For All Computer
  • Last Login For All Users
  • Last Login For Select Users
  • List Domain controllers
  • List Groups (With Count) In Active Directory To TXT
  • List Groups (With Count) In Active Directory To XLSX
  • List Groups For A User(s)
  • List Groups In Active Directory to TXT
  • List Home Directory
  • List Members In A Group(s)
  • Password Generator
  • Ping Test
  • Printer Reset
  • Run A Process Every Few Minutes
  • Search For Files On All Local Drives
  • Show iSCSI Device And Disk Number
  • Uninstall Java

Disable Select users

With this script you can mass disable users and change their display name to show the reason why. Lets say they did not complete a mandatory training and the account needs to be disabled to comply with an audit. This also makes it easy for the rest of the IT team to see exactly why a user was disabled so if the user calls in the HelpDesk wont just turn them back on.
CODE:
Import-Module ActiveDirectory 
$names = Get-Content input.txt 
$add = "Reason to disable user" 
#Process users. 
Foreach ($name in $names) { 
$users = get-aduser -Identity "$name" 
#Process users. 
Foreach ($user in $users) { 
$user >>OldName.log 
Try {Disable-ADAccount -Identity "$user"} 
Catch {Write-output "Unable to Disable $user" >>Error.txt} 
$newname = $user.surname + ", " + $user.GivenName + " ($add)" 
Try {Rename-ADObject -identity "$user" -Newname "$newname" -server 5-E.ME} 
Catch {Write-output "Unable to change DN for $user to $newname" >>ERROR.txt"} 
} 
} 
Use at your own risk
Input File:
UserName
Jim.Bob
SamAccountName
Use at your own risk
Download: Disable Users.zip

Tag(s): Powershell Security


Could you spare a few coins?
Dogecoin - D838u1m9YRdzVVu8CZ1JsR78WHgQmUZSr8
Bitcoin - 13iKLoPXcWEYcGtqCi4UcjGQEs7r6M6LFc
Thank you
  • Home

  • Batch
  • Email
  • Exchange
  • How To
  • Local PC
  • Powershell
  • Security